package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.dto.h5.ProductSkuDto;
import com.atguigu.spzx.model.entity.product.ProductSku;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.model.vo.h5.ProductItemVo;
import com.atguigu.spzx.product.service.ProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @ClassName: ProductController
 * @Package: com.atguigu.spzx.product.controller
 * @Description 商品管理
 * @Author 孤妤
 * @Date: 2023/12/18 16:58
 */
@Tag(name = "商品管理")
@RestController
@RequestMapping("/api/product")
public class ProductController {
    @Autowired
    private ProductService productService;
    @GetMapping("/{pageNum}/{pageSize}")
    @Operation(summary = "分页及条件查询商品")
    public Result<PageInfo<ProductSku>> findProductSkuPage(@PathVariable Integer pageNum,
                                                           @PathVariable Integer pageSize,
                                                           ProductSkuDto productSkuDto){
        PageInfo<ProductSku> productSkuPageInfo = productService.findProductSkuPage(pageNum,pageSize,productSkuDto);
        return Result.build(productSkuPageInfo, ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/item/{skuId}")
    @Operation(summary = "查询商品详情")
    public Result<ProductItemVo> findProductDetailsById(@PathVariable Long skuId){
        ProductItemVo productItemVo = productService.findProductDetailsById(skuId);
        return Result.build(productItemVo,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "查询商品sku信息")
    @GetMapping("/getBySkuId/{skuId}")
    public ProductSku getBySkuId(@PathVariable Long skuId) {
        return productService.getBySkuId(skuId);
    }
}
